package com.example.demo;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.util.ArrayList;

/**
 * Created by sunmo on 2016/11/5.
 */
public class ImageDetailsAdapter extends PagerAdapter {
    private ArrayList<LinearLayout> data;

    public ImageDetailsAdapter(ArrayList<LinearLayout> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(data.get(position));//don`t forget ,or no data will be show
        return data == null ? super.instantiateItem(container, position) : data.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(data.get(position));
    }
}
